using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using Microsoft.Win32;
using System.IO;
using System.Xml.Serialization;
using System.Drawing;

namespace Rapier.Kodachi.Weather
{
    public class WeatherPlugin : Plugin
    {
        #region Properties
        private static WeatherSettings _WeatherSettings;
        public static WeatherSettings WeatherSettings
        {
            get { return _WeatherSettings; }
        }
        #endregion

        #region Data Members
        private Bitmap weatherImage = (Bitmap)Rapier.Kodachi.Weather.Properties.Resources.ResourceManager.GetObject( "_30" );
        #endregion

        #region Constructor
        public WeatherPlugin(Host host) : base(host)
        {
            LoadSettings();
        }
        #endregion

        #region Overrides
        public override string Author
        {
            get { return "El Guapo"; }
        }

        public override string Url
        {
            get { return "http://www.rapiersoftware.com"; }
        }

        public override bool HasSettings
        {
            get { return true; }
        }

        public override bool ShowSettings()
        {
            Settings settings = new Settings(Host);
            settings.ShowDialog();

            return true;
        }

        public override void SaveSettings()
        {
            Host.DataManager.SaveSettings(this, WeatherSettings);
        }

        private void LoadSettings()
        {
            _WeatherSettings = Host.DataManager.LoadSettings<WeatherSettings>(this);
            if (WeatherSettings == null)
            {
                _WeatherSettings = new WeatherSettings();
                WeatherSettings.ExtendedForecastDays = 5;
                WeatherSettings.DefaultLocationText = "Punxsutawney, PA";
                WeatherSettings.DefaultLocationID = "USPA1335";
            }
        }

        public override void UpdateDatabase()
        {
            // Add item
            Item weatherItem = new Item(this, "Direct Item", "Weather", "Weather");
            weatherItem.GetImage = delegate
            {
                return weatherImage;
            };
            weatherItem.DefaultAction = "Current Weather";
            weatherItem.Properties["Weather"] = true;
            Host.AddItem(weatherItem);
            
            // Add actions
            Host.AddAction(new Actions.CurrentWeather(this));
            Host.AddAction(new Actions.Forecast(this));
        }
        #endregion
    }
}
